package cn.stylefeng.guns.modular.gridsystem.config;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.guns.modular.gridsystem.cache.MyStringCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 缓存的配置，默认使用基于内存的缓存，如果分布式部署请更换为redis
 */
@Configuration
public class MyCacheConfig {

    @Bean
    public MyStringCache myStringCache() {
        TimedCache<String, String> timedCache =
//                CacheUtil.newTimedCache(2*60 * 60 * 1000);
                CacheUtil.newTimedCache(0);
        // 定时清理缓存，间隔1秒
        timedCache.schedulePrune(1000);
        return new MyStringCache(timedCache);
    }

}
